#include <QIcon>
#include <QDesktopServices>
#include <QUrl>
#include "guidance_page_style.h"
#include "ui_guidance_page_style.h"
#include "globaldata.h"

GuidancePageStyle::GuidancePageStyle(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::GuidancePageStyle)
{
    ui->setupUi(this);
    initUI();
    m_daemonIpcDbus = new DaemonIpcDbus();
    connect(ui->m_officialWeb,&MyClickWidget::clicked,this,&GuidancePageStyle::on_officialWeb_clicked);
    connect(ui->m_kylinManual,&MyClickWidget::clicked,this,&GuidancePageStyle::on_kylinManual_clicked);
    this->setBackgroundRole(QPalette::Base);
}

GuidancePageStyle::~GuidancePageStyle()
{
    delete ui;
    if (m_daemonIpcDbus)
    {
        delete m_daemonIpcDbus;
        m_daemonIpcDbus = nullptr;
    }
}

void GuidancePageStyle::initUI()
{
    ui->m_pKylinPic->setStyleSheet("border-image:url(:/data/banner.png);border:0px;");

    QPalette peMid;
    QColor colorMid = palette().color(QPalette::Mid);
    peMid.setColor(QPalette::Text,colorMid);
    ui->m_pMoreInfoLink_1->setText(tr("Click "));
    ui->m_pMoreInfoLink_1->setPalette(peMid);

    // QPalette peHighlight;
    // QColor colorHighlight = palette().color(QPalette::Link);
    // peHighlight.setColor(QPalette::Text, colorHighlight);
    // ui->m_pMoreInfoLink_2->setPalette(peHighlight);

    ui->m_pMoreInfoLink_2->setCursor(QCursor(Qt::PointingHandCursor));
    ui->m_pMoreInfoLink_2->setText("<a href = 'https://www.kylinos.cn/support/problem.html'>" + tr("to know more about support") + "</a>");
    ui->m_pMoreInfoLink_2->installEventFilter(this);

    ui->m_pMoreInfoLink_3->setText(tr("，to KylinOS Official Web"));
    ui->m_pMoreInfoLink_3->setPalette(peMid);

    ui->m_pPageTitle->setText(tr("You can get your answers through the ways below"));//"用户可通过以下方式寻求技术支持和服务");
    ui->m_pPageTitle->setPalette(peMid);

    ui->m_pKylinOfficialWeb_1->setProperty("useIconHighlightEffect", 0x2);
    ui->m_pKylinOfficialWeb_1->setProperty("isWindowButton", 0x01);
    ui->m_pKylinOfficialWeb_1->setFlat(true);
    ui->m_pKylinOfficialWeb_1->setIcon(QIcon::fromTheme("software-properties-symbolic"));
    ui->m_pKylinOfficialWeb_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->m_pKylinOfficialWeb_1->adjustSize();
    ui->m_pKylinOfficialWeb_2->setText(tr("To KylinOS Official Web"));
    ui->m_pKylinOfficialWeb_2->setAlignment(Qt::AlignLeft);
    ui->m_pKylinOfficialWeb_2->setAlignment(Qt::AlignVCenter);
    ui->m_pKylinOfficialWeb_2->adjustSize();
    ui->m_pKylinOfficialWeb_3->setText(tr("Access the Web, find the answers."));
    ui->m_pKylinOfficialWeb_3->setAlignment(Qt::AlignLeft);
    ui->m_pKylinOfficialWeb_3->setAlignment(Qt::AlignVCenter);
    ui->m_pKylinOfficialWeb_3->setPalette(peMid);

    ui->m_KylinManual_1->setProperty("useIconHighlightEffect", 0x2);
    ui->m_KylinManual_1->setProperty("isWindowButton", 0x01);
    ui->m_KylinManual_1->setFlat(true);
    ui->m_KylinManual_1->setIcon(QIcon::fromTheme("ukui-sold-symbolic"));
    ui->m_KylinManual_1->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    ui->m_KylinManual_1->adjustSize();
    ui->m_KylinManual_2->setText(tr("Guidance"));//"企业微信");
    ui->m_KylinManual_2->setAlignment(Qt::AlignLeft);
    ui->m_KylinManual_2->setAlignment(Qt::AlignVCenter);
    ui->m_KylinManual_2->adjustSize();
    ui->m_KylinManual_3->setText(tr("Check Manuals to solve the problem."));
    ui->m_KylinManual_3->setAlignment(Qt::AlignLeft);
    ui->m_KylinManual_3->setAlignment(Qt::AlignVCenter);
    ui->m_KylinManual_3->setPalette(peMid);
}
void GuidancePageStyle::changeFont(QFont curFont)
{
    QFont smallFont = GlobalData::getInstance()->getFontSize12px();
    QFont normalFont = curFont;
    //小字
    ui->m_pMoreInfoLink_1->setFont(smallFont);
    ui->m_pMoreInfoLink_2->setFont(smallFont);
    ui->m_pMoreInfoLink_3->setFont(smallFont);
    ui->m_pPageTitle->setFont(smallFont);
    ui->m_pKylinOfficialWeb_3->setFont(smallFont);
    ui->m_KylinManual_3->setFont(smallFont);

    //中等字
    ui->m_pKylinOfficialWeb_2->setFont(normalFont);
    ui->m_KylinManual_2->setFont(normalFont);
}
bool GuidancePageStyle::eventFilter(QObject *obj, QEvent *ev)
{
    if(obj == ui->m_pMoreInfoLink_2)
    {
        if(ev->type() == QEvent::MouseButtonPress)
        {
            /* SDK功能点： 跳转官网主页*/
            GlobalData::SDKPointJumpOfficicalWebsite();

            QDesktopServices::openUrl(QUrl("https://www.kylinos.cn/support/problem.html"));

        }
    }

    return QWidget::eventFilter(obj,ev);
}
void GuidancePageStyle::on_officialWeb_clicked()
{
    /* SDK功能点： 跳转官网主页*/
    GlobalData::SDKPointJumpOfficicalWebsite();
    
    QDesktopServices::openUrl(QUrl("https://www.kylinos.cn/support/problem.html"));
}

void GuidancePageStyle::on_kylinManual_clicked()
{
    if (!m_daemonIpcDbus->daemonIsNotRunning()){
        //增加标题栏帮助菜单、F1快捷键打开用户手册
        m_daemonIpcDbus->showGuide("");
    }
}
